import {
  takeEvery,
  takeLatest,
  throttle,
  take,
  select,
  call,
  put,
} from "redux-saga/effects";
import axios from "axios";
const BASE_URL = "http://localhost:3010";
export function* defSaga() {
  // ReduxComTwo的三个按钮
  yield takeEvery("takeEvery", function* () {
    const state = yield select((state) => state.query);
    const res = yield call(axios.get, BASE_URL + `/agents/${state.id}`, {});
    console.log(res);
    console.log("1----takeEvery");
    yield put({
      type: "success_data",
      ...res.data,
    });
  });
  yield takeLatest("takeLatest", function* () {
    const state = yield select((state) => state.query);
    const res = yield call(axios.get, BASE_URL + `/agents/${state.id}`, {});
    console.log(res);
    console.log("2----takeLatest");
    yield put({
      type: "success_data",
      ...res.data,
    });
  });
  yield throttle(2000, "throttle", function* () {
    const state = yield select((state) => state.query);
    const res = yield call(axios.get, BASE_URL + `/agents/${state.id}`, {});
    console.log(res);
    console.log("3----throttle");
    yield put({
      type: "success_data",
      ...res.data,
    });
  });
  // ReduxComOne的一个按钮
  yield take("take");
  console.log("匹配到了take");
  // ReduxComLoginAndList的功能模块
}
